package mybatis;

import java.util.HashMap;
import java.util.Map;

import mybatis.util.PropertiesFileUtil;

/**
 * 代码生成类
 * Created by src on 2018/6/25.
 * 放在Dao层下面
 */
public class Generator {
	//Model + ModelExample 存放的路径和包名
	private static String targetProjectDao = ".";
	private static String modelPack = "cn.screator.charge.model.entity";

	//Mapper.java + Mapper.xml 存放路径和包名
	private static String mapperPack = "cn.screator.charge.mybatis.mapper";
//	private static String targetProjectSql = "../../services/dao/src/main/resources/";
	private static String targetProjectSql = "./src/main/resources/";
	private static String sqlmapperPack = "mapper";


	//Repository 存放的路径和包名
//	private static String targetRepository = "../../services/service";
	private static String targetRepository = ".";
	private static String repositoryPack = "cn.screator.charge.service";

	// 远程接口Facade 的路径和包名
//	private static String targetProjectRpcApi = "../../services/service";
	private static String targetProjectRpcApi = ".";
	private static String rpcPack = "cn.screator.charge.service.api";


	// 远程接口FacadeImpl 实现类 的路径和包名
//	private static String targetProjectRpcService = "../../services/service";
	private static String targetProjectRpcService = ".";
	private static String rpcServerPack = "cn.screator.charge.service.api.impl";


	//数据库名
	private static String DATABASE = "jplatform_v4_cdz";
	//需要生成的数据表前缀
	private static String TABLE_PREFIX = "cdz_";
    //不需要生成的数据表前缀
    private static String EXCLUDE_PREFIX = "cdz_v_";

	//创建人
	private static String author = "clg";
	private static String JDBC_DRIVER = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.driver");
	private static String JDBC_URL = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.url");
	private static String JDBC_USERNAME = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.username");
	private static String JDBC_PASSWORD = PropertiesFileUtil.getInstance("generator").get("generator.jdbc.password");

	// 需要insert后返回主键的表配置，key:表名,value:主键名
	private static Map<String, String> LAST_INSERT_ID_TABLES = new HashMap<>();
	static {
		LAST_INSERT_ID_TABLES.put("wechat_keyword_activity", "id");
	}

	/**
	 * 自动代码生成
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		MybatisGenerator.generator(
				null,//是否需要继承某个类，此值是全路径类名
				true,//是否生成Facade 层
				targetProjectDao,//当前执行此方法的模块用于确认base-path 例如 testgenerator/testgenerator-dao
				targetProjectSql,//sqlmap存放 目标项目路径 例如 testgenerator/testgenerator-rpc-service/src/main/resources/
				targetProjectRpcApi,// rpc 接口项目模块  例如 testgenerator/testgenerator-rpc-facade
				targetProjectRpcService,// rpc 接口 实现 项目模块  例如 testgenerator/testgenerator-rpc-service
				targetRepository,//Repository 存放在哪个项目
				modelPack,//model包 例如： com.test.dao.model
				mapperPack,//mapper文件包  com.test.dao.mapper
				repositoryPack,//repository文件包  例如：com.test.dao.repository
				sqlmapperPack,//mapper.xml文件包  mapper
				rpcPack,//rpc 对外接口层的包
				rpcServerPack,//rpc  实现层
				JDBC_DRIVER,
				JDBC_URL,
				JDBC_USERNAME,
				JDBC_PASSWORD,
				DATABASE,//数据库
				TABLE_PREFIX,//表前缀，主要是用来匹配需要生成哪些表数据
				EXCLUDE_PREFIX,//表前缀，主要是用来匹配不需要生成哪些表数据
				LAST_INSERT_ID_TABLES,//需要insert后返回主键的表配置，key:表名,value:主键名
				author
		);
	}
}